<?php
class SiteInSightCMSDB
{
	private $db;

	public function SiteInSightCMSDB()
	{
		if (!class_exists('JFactory'))
		{
			$JoomlaRoot = realpath(dirname(__FILE__) . '/../../../../');
			define('_JEXEC', 1);
			define('JPATH_BASE', $JoomlaRoot);
			define('DS', DIRECTORY_SEPARATOR);
			require_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php');
			require_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php');
			require_once(JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php');
			require_once(JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'application' . DS . 'application.php');
			JApplication::_createConfiguration($JoomlaRoot . '/configuration.php');
		}
		$this->db =& JFactory::getDBO();
	}

	public function getResult($query, $num_prefixes = 1)
	{
		$prefixArray = array();
		for ($i = 0; $i < $num_prefixes; $i++)
		{
			$prefixArray[] = '#__';
		}
		$query = vsprintf($query, $prefixArray);
		$this->db->setQuery($query);
		return $this->db->loadAssocList();
	}

	public function executeQuery($query, $num_prefixes = 1)
	{
		$prefixArray = array();
		for ($i = 0; $i < $num_prefixes; $i++)
		{
			$prefixArray[] = '#__';
		}
		$query = vsprintf($query, $prefixArray);
		$this->db->setQuery($query);
		return $this->db->query();
	}
}
